<?php
namespace app\admin\controller;

use app\admin\model\Article as ArticleModel;
use think\Db;
use think\Loader;

class System extends Base
{
    // 系统设置
    public function index()
    {
        $id   = input('id');
        $info = Db::name('system')->find($id);

        if (request()->isPost()) {
            $data = [
                'id'         => input('id'),
                'updatetime' => time(),
            ];

            if(input('webname')){
                $data['webname'] = input('webname');
            }
            if(input('url')){
                $data['url'] = input('url');
            }
            if(input('keywords')){
                $data['keywords'] = str_replace('，', ',', input('keywords'));
            }
            if(input('description')){
                $data['description'] = input('description');
            }

            $result = Db::name('system')->update($data);
            if ($result !== false) {
                $this->success('修改系统设置成功！', 'index');
            } else {
                $this->error('修改系统设置失败！');
            }
            return;
        }

        $this->assign('system', $info);

        return $this->fetch();
    }


}
